#include <stdio.h>
#include <avr/io.h>
#include <avr/iom128rfa1.h>
#include "contiki.h"
#include "contiki-conf.h"
#include "contiki-net.h"
#include "contiki-lib.h"
#include "dev/rs232.h"
#include "util.h"
#include "printSomething.h"

PROCESS(hello_world_process, "Hello World Process");
AUTOSTART_PROCESSES(&hello_world_process);


PROCESS_THREAD(hello_world_process, ev, data)
{
	static struct etimer timer;
	static unsigned char ledCounter = 0;
	PROCESS_BEGIN()
		;

		SET_BIT(DDRE, 2);
		SET_BIT(DDRE, 3);
		SET_BIT(DDRE, 4);
		SET_BIT(PORTE, 2);
		CLR_BIT(PORTE, 3);
		SET_BIT(PORTE, 4);
		etimer_set(&timer, CLOCK_SECOND);

		while (1)
		{
			PROCESS_WAIT_EVENT();
			if (ev == PROCESS_EVENT_TIMER)
			{
				ledCounter++;
				PORTE = ledCounter << 2;
				printf("Hello World! ledCounter=%d\n", ledCounter);
				printSomething(process_current->name);
				etimer_set(&timer, CLOCK_SECOND);
			}
		}

	PROCESS_END();
}
